#include "userInformantion.h"
UserInformation::UserInformation(QString name)
{
    setupUi(this);
    this->setWindowTitle(tr("容量信息"));
    this->username->setText(name);
    setUseage(0);
}
void UserInformation::setUseage(long tmp)
{
    double usage=(double)(tmp/1024/1024);
    QString sizeUsed=QString::number(usage);
    sizeUsed.append("M");
    this->sizeLabel->setText(sizeUsed);
    int user_size=USER_SIZE/1024/1024;
    int Useage=(int)(usage*100/user_size);
    if(Useage<50)
    {
        this->progressBar->setValue(Useage);
        this->progressBar->setStyleSheet("QProgressBar:horizontal {border:1px solid gray;border-radius: 10px;text-align: center; background: white;padding: 1px;} QProgressBar::chunk:horizontal { border-radius: 10px;background-color: rgb(170, 255, 0); }");
    }
    else if(Useage<80)
    {
        this->progressBar->setValue(Useage);
        this->progressBar->setStyleSheet("QProgressBar:horizontal {border:1px solid gray;border-radius: 10px;text-align: center; background: white;padding: 1px;} QProgressBar::chunk:horizontal { border-radius: 10px;background-color: rgb(255, 170, 0); }");
    }
    else if(Useage<=100)
    {
        this->progressBar->setValue(Useage);
        this->progressBar->setStyleSheet("QProgressBar:horizontal {border:1px solid gray;border-radius: 10px;text-align: center; background: white;padding: 1px;} QProgressBar::chunk:horizontal { border-radius: 10px;background-color: rgb(255, 0, 0); }");
    }
    else
    {
        QTextCodec* codec=QTextCodec::codecForLocale();
        QTextCodec::setCodecForTr(codec);
        sizeUsed.append("超出容量");
        this->sizeLabel->setText(tr(sizeUsed.toStdString().c_str()));
        this->progressBar->setValue(100);
        this->progressBar->setStyleSheet("QProgressBar:horizontal {border:1px solid gray;border-radius: 10px;text-align: center; background: white;padding: 1px;} QProgressBar::chunk:horizontal { border-radius: 10px;background-color: rgb(255, 0, 0); }");
    }
}

void UserInformation::closeEvent(QCloseEvent *event)
{
    this->hide();
    event->ignore();
}
